#!/usr/bin/env bash
# DNS 工具子菜单

dns_menu_show() {
  clear
  echo -e "${YELLOW}【DNS 工具】${RESET}"
  echo -e "  ${GREEN}1.${RESET} 设置系统 DNS (常用/自定义)"
  echo -e "  ${GREEN}2.${RESET} 恢复系统 DNS"
  echo -e "  ${GREEN}3.${RESET} 查看当前 DNS 配置"
  echo -e "  ${GREEN}4.${RESET} 多节点 DNS 解析对比"
  echo -e "  ${GREEN}5.${RESET} DNS 污染检测"
  echo -e "  ${GREEN}6.${RESET} DNS 性能测速"
  echo -e "  ${GREEN}7.${RESET} 一键：设置 DNS + 完整更新"
  echo ""
  echo -e "  ${GREEN}0.${RESET} 返回主菜单"
}

dns_menu_loop() {
  while true; do
    dns_menu_show
    read -rp "请选择 [0-7]: " a
    case "$a" in
      1) pick "设置系统 DNS";                 run_or_stub dns_set_interactive ;;
      2) pick "恢复系统 DNS";                 run_or_stub dns_restore_default ;;
      3) pick "查看当前 DNS 配置";             run_or_stub dns_show_config ;;
      4) pick "多节点 DNS 解析对比";           run_or_stub dns_compare_resolution ;;
      5) pick "DNS 污染检测";                 run_or_stub dns_pollution_check ;;
      6) pick "DNS 性能测速";                 run_or_stub dns_latency_benchmark ;;
      7) pick "一键：设置 DNS + 完整更新";     run_or_stub dns_set_and_full_update ;;
      0) break ;;
      *) echo -e "${RED}${BOLD}❌ 无效输入，请重试${RESET}" ;;
    esac
    [[ "$a" != 0 ]] && read -rp "按回车键返回上级..."
  done
}
